package com.example.administrator.idocment;

import android.content.Context;

import com.example.administrator.idocment.docment.AudioFind;
import com.example.administrator.idocment.docment.AviFind;
import com.example.administrator.idocment.docment.DocFind;
import com.example.administrator.idocment.docment.PicFind;
import com.example.administrator.idocment.docment.ZipFind;
import com.example.administrator.idocment.docment.tool.CheckEnum;

import java.util.List;

import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2017/7/13 0013.
 */
public class LocalFileTool
{






    public static final  int picFlag=1;
    public static final  int aviFlag=2;
    public static final  int volumFlag=3;
    public static final  int docFlag=4;
    public static final  int zipFlag=5;

   // final static Object lock=new Object();

    /*相册目录，相册*/





     public static void readFile(final int flag, final Context context, final IReadCallBack iReadCallBack)
     {
         CheckEnum.init();
         Observable.just(context).map(new Func1<Context, List<Object>>() {
             @Override
             public List<Object> call(Context context1) {


                    List<Object> paths = null;


                    BaseTypeFind baseTypeFind=null;
                    switch (flag)
                    {
                        case picFlag:
                            baseTypeFind=new PicFind(context);
                            break;
                        case aviFlag:
                            baseTypeFind=new AviFind(context);
                            break;
                        case volumFlag:
                            baseTypeFind=new AudioFind(context);
                            break;
                        case docFlag:
                            baseTypeFind=new DocFind(context);
                            break;
                        case zipFlag:
                            baseTypeFind=new ZipFind(context);
                            break;
                    }

                    baseTypeFind.select();
                    paths=baseTypeFind.getListInfo();

                    return paths;


             }
         }).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).
                 subscribe(new Action1<List<Object>>() {
                     @Override
                     public void call(List<Object> object) {

                         if (iReadCallBack != null)
                             iReadCallBack.callBack(object);
                     }
                 });

     }



   public interface IReadCallBack<T>
    {
        void callBack(T localPath);
    }

}
